package com.o2o.cleaning.month.platform.ebusiness_plat.taobao

import com.alibaba.fastjson.{JSON, JSONObject}
import com.o2o.utils.Iargs
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.SparkSession

/**
  * @ Auther: o2o-rd-0008
  * @ Date:   2020/11/6 10:46
  * @ Param:  ${PARAM}
  * @ Description:
  */
object zhengfuDeal {
  def main(args: Array[String]): Unit = {
    val spark = SparkSession.builder()
      .appName(s"${this.getClass.getSimpleName}")
      .config("spark.debug.maxToStringFields", "2000")
      .config("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
//        .master("local[*]")
      .getOrCreate()

    val sc = spark.sparkContext
    sc.hadoopConfiguration.set("fs.s3a.access.key", Iargs.OBSACCESS)
    sc.hadoopConfiguration.set("fs.s3a.secret.key", Iargs.OBSSECRET)
    sc.hadoopConfiguration.set("fs.s3a.endpoint", Iargs.OBSENDPOINT)
    sc.setLogLevel("WARN")

  import org.apache.spark.sql.functions._
    val value: RDD[String] = spark.read.orc("s3a://dws-data/g_data/2020/shuang11/2020_11_1_2020_tui/taobao/")
      .drop("timeStamp").withColumn("timeStamp", lit("1603987200"))
      .toJSON.rdd.map(lines => {
      val nObject: JSONObject = JSON.parseObject(lines)
      val is_jhs: Boolean = nObject.getString("is_jhs").toBoolean
//      val is_newProduct: Boolean = nObject.getString("is_newProduct").toBoolean
//      val is_o2o: Boolean = nObject.getString("is_o2o").toBoolean
      val is_oversea: Boolean = nObject.getString("is_oversea").toBoolean

      nObject.put("is_jhs", is_jhs)
//      nObject.put("is_newProduct", is_newProduct)
//      nObject.put("is_o2o", is_o2o)
      nObject.put("is_oversea", is_oversea)

      nObject.toString
    })

    spark.read.json(value)

     .write.orc("s3a://dws-data/g_data/2020/shuang11/2020_11_1_2020_tui/taobao_new/")
  }
}
